package leetcode;

public class MyPow {
    public static void main(String[] args) {
        MyPow myPow = new MyPow();
        System.out.println(myPow.myPow(2.00000, 10));
    }

    public double myPow(double x, int n) {
        if (n == 0) {
            return 1;
        }
        if (n < 0) {
            x = 1 / x;
            n = Math.abs(n);
        }
        if (n == 1) {
            return x;
        }
        double res = myPow(x, n / 2) * myPow(x, n / 2);
        if (n % 2 != 0) {
            res *= x;
        }
        return res;
    }
}
